let input = document.getElementsByTagName('input');
let select = document.getElementsByTagName('select');
for (let i of select) {
    i.addEventListener('change', Select, false);
}
for (let i of input){
    i.addEventListener('input', lister, false);
    i.addEventListener('change',delet,false);
}
input[2].addEventListener('input', validate, false);
function lister(e) {
    console.log(e);
    let i = e.target;
    if (i.validity.patternMismatch) {
        if (i.name == "username") {
            i.setCustomValidity('用户名不能有空格,长度为4-10位');
            let wors = document.getElementById(i.name);
            wors.innerHTML = "<span style=\"color: red;font-size: 8px;display: block;\">用户名不能有空格,长度为4-10位</span>"
            console.log(i.parentElement);
        }
        if (i.name == "password") {
            i.setCustomValidity('至少8个字符，至少1个字母，1个数字和1个特殊字符');
            let wors = document.getElementById(i.name);
            wors.innerHTML = "<span style=\"color: red;font-size: 8px;display: block;\">至少8个字符，至少1个字母，1个数字和1个特殊字符</span>"
        }
        if (i.name == "name") {
            i.setCustomValidity('昵称必须是中文');
            let wors = document.getElementById(i.name);
            wors.innerHTML = "<span style=\"color: red;font-size: 8px;display: block;\">昵称必须是中文</span>"
        }
        if (i.name == "phone") {
            i.setCustomValidity('请输入正确的电话号码');
            let wors = document.getElementById(i.name);
            wors.innerHTML = "<span style=\"color: red;font-size: 8px;display: block;\">请输入正确的电话号码</span>"
        }
        if (i.name == "emile") {
            i.setCustomValidity('请输入正确的邮箱格式');
            let wors = document.getElementById(i.name);
            wors.innerHTML = "<span style=\"color: red;font-size: 8px;display: block;\">请输入正确的邮箱格式</span>"
        }
    }
}

function delet(e) {
    let i = e.target;
    i.setCustomValidity("");
    let wors = document.getElementById(i.name);
    wors.innerHTML = "";
}

function validate() {
    let pass = input[1].value;
    let Cpass = input[2].value;
    if (pass != Cpass) {
        let wor = document.getElementById(input[2].name);
        wor.innerHTML = "<span style=\"color: red;font-size: 8px;display: block;\">请输入正确的密码</span>"
        return false;
    } else {
        let worss = document.getElementById(input[2].name);
        worss.innerHTML = "";
        return true;
    }
}
function Select() {
    let value_1 = select[0].value;
    let value_2 = select[1].value;
    if (value_1 == "您的班级") {
        let wor = document.getElementById(select[0].name);
        wor.innerHTML = "<span style=\"color: red;font-size: 8px;display: block;\">请选择班级</span>"
        return false;
    }
    if (value_2 == "您的性别") {
        let wor = document.getElementById(select[1].name);
        wor.innerHTML = "<span style=\"color: red;font-size: 8px;display: block;\">请选择性别</span>"
        return false;
    }
    document.getElementById(select[0].name).innerHTML = "";
    document.getElementById(select[1].name).innerHTML = "";
    return true;
}

function Acess() {
    let pass = validate();
    let select = Select();
    if (pass && select) {
        return true;
    } else {
        return false;
    }

}